/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package personInfoTests;

import java.text.DateFormat;
import java.util.Locale;
import model.Constants;
import java.util.Calendar;
import java.util.Date;
import javax.swing.text.PlainDocument;
import model.personInfo.Origin;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;

/**
 *
 * @author Slayer
 */
public class OriginTest {

    private Origin origin;
    private final Date BIRTH_DAY;
    private final String PLACE = "Kriviy Rig";
    private final String SEPARATOR = Constants.LINE_SEPARATOR;

    public OriginTest() {
        Calendar calendar = Calendar.getInstance();
        calendar.set(1991, 2, 5);
        BIRTH_DAY = calendar.getTime();
    }

    @Before
    public void setUp() {
        origin = new Origin(BIRTH_DAY, PLACE);
    }

    @After
    public void tearDown() {
    }

    @Test(expected = IllegalArgumentException.class)
    public void shouldThrowIllegalArgumentExceptionWhenPassNullBirthDay() {
        origin = new Origin(null, PLACE);
    }

    @Test
    public void shouldReturnBirthDayWhenGet() {
        //given
        Date expected = BIRTH_DAY;
        //then
        assertEquals(expected, origin.getBirthDay());
    }

    @Test
    public void shouldReturnPlaceOfBirthWhenGet() {
        //given
        String expected = PLACE;
        //then
        assertEquals(expected, origin.getPlace());
    }

    @Test
    public void testToString() {
        //given
        String expected = "Date of birth: "
                + DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.ENGLISH).format(BIRTH_DAY)
                + SEPARATOR
                + "Place of birth: " + PLACE + SEPARATOR;
        //then
        assertEquals(expected, origin.toString());
    }

    @Test
    public void testClone() {
        //given
        String expected = origin.toString();
        //then
        assertEquals(expected, origin.clone().toString());
    }

    @Test
    public void testEquals() {
        //given
        Origin expected = origin;
        //then
        assertEquals(expected, origin.clone());
    }
}
